﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using SEO.Business;

/// <summary>
/// 今日关键字
/// </summary>
public partial class TodayKeywordsList : AdminPage
{
    /// <summary>
    /// 名称
    /// </summary>
    protected string Name
    {
        get { return ViewState["Name"] == null ? "" : ViewState["Name"].ToString(); }
        set { ViewState["Name"] = value; }
    }

    /// <summary>
    /// 分类ID
    /// </summary>
    protected int SortID
    {
        get { return ViewState["SortID"] == null ? 0 : Convert.ToInt32(ViewState["SortID"]); }
        set { ViewState["SortID"] = value; }
    }

    protected int nNum = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            InitSort();
            InitData();
        }
    }

    /// <summary>
    /// 权限控制
    /// </summary>
    /// <returns></returns>
    public override long GetNeededFeatures()
    {
        return AdminFEATURE.TodayKeywordsList;
    }

    protected void InitSort()
    {
        DataTable dtSort = GetAllSort();
        ddlSort.Items.Clear();
        ddlSort.Items.Add(new ListItem("所有分类", "0"));
        foreach (DataRow drSort in dtSort.Rows)
        {
            ddlSort.Items.Add(new ListItem(drSort["Name"].ToString(), drSort["ID"].ToString()));
        }
        dtSort.Dispose();
    }

    /// <summary>
    /// 页面初始化
    /// </summary>
    protected void InitData()
    {
        int nRecordCount = 0;
        int nPageCount = 0;
        DateTime dBeginTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));
        //信息列表绑定
        DataTable dt = new BisKeywords().GetTodayList(Name, SortID, dBeginTime, dBeginTime.AddDays(1),anpPage.CurrentPageIndex, anpPage.PageSize, ref nPageCount, ref nRecordCount);
        nNum = (anpPage.CurrentPageIndex - 1) * anpPage.PageSize;
        nNum++;
        //dt.Columns.Add("FirstCount", typeof(string));
        //if (dt != null && dt.Rows.Count > 0)
        //{
        //    string strIDList = string.Empty;
        //    foreach (DataRow dr in dt.Rows)
        //    {
        //        strIDList += (string.IsNullOrEmpty(strIDList) ? "" : ",") + dr["ID"].ToString();
        //    }
        //    if (!string.IsNullOrEmpty(strIDList))
        //    {
        //        DateTime dBeginTime =Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));
        //        DataTable dtReport = new BisKeywordsReport().GetKeysFirstCountList(strIDList, 1, dBeginTime, dBeginTime.AddDays(1));
        //        if (dtReport != null && dtReport.Rows.Count > 0)
        //        {
        //            foreach (DataRow dr in dt.Rows)
        //            {
        //                foreach (DataRow drReport in dtReport.Rows)
        //                {
        //                    if (Convert.ToInt32(dr["ID"]) == Convert.ToInt32(drReport["KeywordsID"]))
        //                    {
        //                        dr["FirstCount"] = drReport["FirstCount"];
        //                        break;
        //                    }
        //                }
        //            }
        //        }
        //        dtReport.Dispose();
        //    }
        //}
        anpPage.RecordCount = nRecordCount;
        if (nRecordCount == 0)
        {
            noData.Style["display"] = "block";
        }
        else
        {
            noData.Style["display"] = "none";
        }
        rptKeywords.DataSource = dt;
        rptKeywords.DataBind();
        dt.Dispose();

        anpPage.CustomInfoHTML = string.Format("<div class=\"pagetag\">当前第<b>{0}</b>/<b>{1}</b>页 共<b>{2}</b>条记录</div>", new object[] { anpPage.CurrentPageIndex, anpPage.PageCount, anpPage.RecordCount });
    }


    /// <summary>
    /// 分页事件
    /// </summary>
    /// <param name="src"></param>
    /// <param name="e"></param>
    protected void anpPage_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        anpPage.CurrentPageIndex = e.NewPageIndex;
        InitData();
    }

    /// <summary>
    /// 查询
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
       
        Name = txtName.Text.Trim();
        SortID = Convert.ToInt32(ddlSort.SelectedValue);
        anpPage.CurrentPageIndex = 1;

    }

    /// <summary>
    /// 重置
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnReset_Click(object sender, EventArgs e)
    {
        InitData();
    }
}